package main.Q1101_1200;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Q1171_1180 {
    public static void main(String[] args) {
        System.out.println("Question1161：");
        System.out.println("Question1162：地图分析");
        System.out.println("Question1163：");
        System.out.println("Question1164：");
        System.out.println("Question1165：");
        System.out.println("Question1166：");
        System.out.println("Question1167：");
        System.out.println("Question1168：");
        System.out.println("Question1169：");
        System.out.println("Question1170：");
    }
}

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

class Question1171 {
    public ListNode removeZeroSumSublists(ListNode head) {
        ListNode vir = new ListNode(0);
        vir.next = head;
        Map<Integer, ListNode> map = new HashMap<>();
        int pre = 0;
        for (ListNode node = vir; node != null; node = node.next) {
            pre += node.val;
            map.put(pre, node);
        }
        pre = 0;
        for (ListNode node = vir; node != null; node = node.next) {
            pre += node.val;
            node.next = map.get(pre).next;
        }
        return vir.next;
    }
}